#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time        : 2021/11/25 16:12
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : lena.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage import transform as tf
from skimage.io import imread
from skimage.feature import match_descriptors, plot_matches, ORB
import matplotlib.pyplot as plt

IM_PATH = "../experiment_fig/lena.jpg"
im = imread(IM_PATH, as_gray=True)
rotate_im = tf.rotate(im, angle=45)  # 逆时针旋转45°
# 提取原始图像关键点和描述符
extractor1 = ORB(n_keypoints=400)
extractor1.detect_and_extract(im)
key_points1, descriptors1 = extractor1.keypoints, extractor1.descriptors
# 提取旋转后的图像关键点和描述符
extractor2 = ORB(n_keypoints=400)
extractor2.detect_and_extract(rotate_im)
key_points2, descriptors2 = extractor2.keypoints, extractor2.descriptors
# 匹配两幅图像描述符
matches12 = match_descriptors(descriptors1, descriptors2)
fig, ax = plt.subplots(nrows=1, ncols=1)
plot_matches(ax, im, rotate_im, key_points1, key_points2, matches12,matches_color="purple")
plt.show()
